home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
program
/
snpd9611.zip
/
PI.C
< prev
next >
Wrap
Text File
|
1996-11-24
|
2KB
|
62 lines
.I 0 2
/* +++Date last modified: 24-Sep-1996 */
.I 3 25
** Uses far arrays when/where required so may be compiled in any memory model
**
** The formula that most use (including the one in the Snippets) is the
** classic Machin formula, with the Gregory series.
**
** pi=16arctan(1/5)-4arctan(1/239)
**
** And use the traditional Gregory arctangent series to calculate the
** arctangents. That's the:
**
** arctan(x)=x-(x^3)/3+(x^5)/5-(x^7)/7.....
**
** With 1/5 and 1/239, it would be:
**
** arctan(x)=1/5-1/(3*5^3)+1/(5*5^5)-1/(7*5^7)...
** arctan(x)=1/239-1/(3*239^3)+1/(5*239^5)-1/(7*239^7)....
**
** Doing the multi-precision isn't too hard, since we don't really need to
** have a general purpose math package. We can hardwire it all.
**
** Due to the % operator, ms[i] < (temp * (239**2)) so
** temp < 3759 and i < 1879, it fails at the 1879th term which translates to
** 1879 * log10(239**2) == 8941th decimal.
**
** In practice we get a few more digits, (2 -> 8943th)
.D 4 1
.I 13 5
long i, line;
long col, col1;
long loc, FAR stor[4096];
static void PASCAL shift(long FAR *l1, long FAR *l2, long lp, long lmod)
.D 14 5
.I 26 1
static void PASCAL yprint(long m)
.D 27 1
.I 33 1
if (++col1 == 5)
.D 34 1
.I 36 1
printf("\nL%04ld:", ++line);
.D 37 1
.I 46 1
static void PASCAL xprint(long m)
.D 47 1
.I 73 1
static void PASCAL memerr(int errno)
.D 74 1
.I 94 1
if (NULL == mf)
.D 95 1
.I 97 1
if (NULL == ms)
.D 98 1
.I 114 1
printf("\nL%04ld: 3.", ++line);
.D 115 1